package com.open.capacity.user.controller;

import com.open.capacity.common.model.Group;
import com.open.capacity.common.model.SysUser;
import com.open.capacity.common.web.PageResult;
import com.open.capacity.common.web.Result;
import com.open.capacity.user.service.GroupService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

@RestController
@RequestMapping("/group")
@Api(tags = "小组管理")
public class GroupController {
    @Autowired
    private GroupService groupService;

    /**
     * 获取教师管理的小组
     * @param params
     * @return
     */
    @PostMapping("/getGroupByTeacher")
    @ApiOperation(value = "获取教师管理的小组")
    public PageResult getGroupByTeacher(@RequestParam Map<String,Object> params){
        return groupService.selectGroupByTeacher(params);
    }

    /**
     * 添加小组
     * @param group 小组实体类型
     * @return
     */
    @PostMapping("/addGroup")
    @ApiOperation(value = "添加小组")
    public Result addGroup(@RequestBody Group group){
        return groupService.addGroup(group);
    }

    /**
     * 删除单个小组
     * @param id    小组id
     * @return
     */
    @GetMapping("/deleteGroupById")
    @ApiOperation(value = "删除单个小组")
    public Result deleteGroupById(@RequestParam int id){
        return groupService.deleteGroupById(id);
    }

    /**
     * 修改小组状态
     * @param params
     * @return
     */
    @GetMapping("/updateGroupType")
    @ApiOperation(value = "修改小组状态")
    public Result updateGroupType(@RequestParam Map<String,Object> params){
        return groupService.updateGroupType(params);
    }

    /**
     * 获取小组成员及未分配小组成员（教师分配小组成员）
     * @param id
     * @return
     */
    @GetMapping("/getCheckGroupMember")
    @ApiOperation(value = "获取小组成员及未分配小组成员（教师分配小组成员）")
    public Result getCheckGroupMember(@RequestParam int id){
        return groupService.getCheckGroupMember(id);
    }

    /**
     * 添加小组成员
     * @param grouid
     * @param ids
     * @return
     */
    @GetMapping("/addGroupMember")
    @ApiOperation(value = "添加小组成员")
    public Result addGroupMember(@RequestParam int grouid,@RequestParam List<Long> ids){
        Map params = new HashMap();
        params.put("grouid", grouid);
        params.put("ids",ids);
        return groupService.addGroupMember(params);
    }

    /**
     * 移除小组成员
     * @param grouid
     * @param ids
     * @return
     */
    @GetMapping("/removeGroupMember")
    @ApiOperation(value = "移除小组成员")
    public Result removeGroupMember(@RequestParam int grouid,@RequestParam List<Long> ids){
        Map params = new HashMap();
        params.put("grouid", grouid);
        params.put("ids",ids);
        return groupService.removeGroupMember(params);
    }

    /**
     * 修改小组信息
     * @param group
     * @return
     */
    @PostMapping("/updateGroup")
    @ApiOperation(value = "修改小组信息")
    public Result updateGroup(@RequestBody Group group){
        return groupService.updateGroup(group);
    }

    /**
     * 通过用户查询小组信息
     * @param userid
     * @return
     */
    @GetMapping("/getGroupByMember")
    @ApiOperation(value = "通过用户查询小组信息")
    public Result getGroupByMember(@RequestParam Long userid){
        return groupService.selectGroupByMember(userid);
    }

    /**
     * 查询小组内成员
     * @param params
     * @return
     */
    @PostMapping("/selectUserByGroup")
    @ApiOperation(value = "查询小组内成员")
    public PageResult selectUserByGroup(@RequestParam Map<String,Object> params){
        return groupService.selectUserByGroup(params);
    }

    /**
     * 根据班主任ID查看小组
     * @param params
     * @return
     */
    @GetMapping("/getGroup")
    public Result getGroup(@RequestParam Map<String,Object> params){
        return groupService.getGroup(params);
    }

    /**
     * 根据班主任ID获取所有小组成员
     * @param teachid
     * @return
     */
    @GetMapping("/getGroupUserByTeacher")
    public List<SysUser> getGroupUserByTeacher(Long teachid){
        return groupService.getGroupUserByTeacher(teachid);
    }
}
